
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
{
    is_chrome = true;
}
else
{
    is_chrome = false;
}

function plural(n)
{
    if (n%10==1&&n%100!=11)return 0;
    if (n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)) return 1;
    return 2;
}
function ending(n,one,three,five)
{
    var x =plural(n)
    return ( 0 == x ? one : ( 1 == x ? three : five ) )
}
function secs_to_rus(secs , d, h, m, s)
{
    var days = Math.floor(secs / 24 / 60 / 60);
    var hours = Math.floor(secs / 60 / 60) % 24;
    var minutes = Math.floor(secs / 60) % 60;
    var seconds = Math.floor(secs) % 60;

    var ret = '';
    if(!d && days) ret +=' '+ days + ending(days, ' день', ' дня', ' дней');
    if(!h && (hours || days)) ret +=' '+ hours + ending(hours, ' час', ' часа', ' часов');
    if(!m &&(minutes || hours || days)) ret +=' '+ minutes + ending(minutes, ' минута', ' минуты', ' минут');
    if(!s && (seconds || minutes || hours || days)) ret +=' '+ seconds + ending(seconds, ' секунда', ' секунды', ' секунд');

    return ret;
    
}

// server time - object time
function timer_diff(time)
{
    var answer = {
        old:0,
        sec:0
    };
    var realServerTime = _globals["servertime"]-0 + _globals["time_left_rpc"]-0;
    
    if(realServerTime > time)
    {
        answer.old = 1;
        answer.sec = realServerTime - time;
    }
    else
    {
        answer.sec = time - realServerTime;
    }
    return answer;
}


function getRandomInt(min, max)
{
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function _new(name)
{
    return document.createElement(name);
}

function getBounds(obj){
    var w=obj.offsetWidth;
    var h=obj.offsetHeight;
    var x=y=0;
    while(obj){
        x+=obj.offsetLeft;
        y+=obj.offsetTop;
        obj=obj.offsetParent;
    }
    return{
        left:x,
        top:y,
        x:x,
        y:y,
        width:w,
        height:h
    };
}

function trace_n()
{
    trace ('--------------------------');
}

function preload_image(src)
{
    pic = new Image();
    pic.src = src;
}
